package com.example.moviegroup.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;

import com.example.moviegroup.R;
import com.example.moviegroup.app.IApplication;
import com.example.moviegroup.app.Logger;

public class MyDianzanView extends View {

    private String num = "1025";
    private Bitmap bitmap;
    private int resId;

    public MyDianzanView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    public MyDianzanView(Context context, AttributeSet attrs) {
        super(context, attrs);
        TypedArray ta = context.obtainStyledAttributes(attrs,
                R.styleable.MyDianzan);
        resId = ta.getResourceId(R.styleable.MyDianzan_src,
                R.mipmap.ic_launcher);
        ta.recycle();
        init();
    }

    public MyDianzanView(Context context) {
        super(context);
        init();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
       Paint paint=new Paint();
		canvas.drawBitmap(bitmap, 0, 0, null);

		paint.setTextSize(30);
		Rect bounds = new Rect();
		paint.getTextBounds(num, 0, num.length(), bounds);
		int textW = bounds.width();
		int textH = bounds.height();
		canvas.drawText(num, bitmap.getWidth()+5 ,15, paint);
		paint.setTextSize(25);
		canvas.drawText("+", bitmap.getWidth()+textW+5 ,-textH+20, paint);

    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    //    	 TODO Auto-generated method stub
        int wid = MeasureSpec.makeMeasureSpec(100, MeasureSpec.AT_MOST);
        int hei = MeasureSpec.makeMeasureSpec(100, MeasureSpec.AT_MOST);
        super.onMeasure(wid, hei);
       // setMeasuredDimension(200,200);
    }

    public void init() {

        bitmap = BitmapFactory.decodeResource(getResources(), resId);
    }
}
